/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Longda on 2021/4/14.
//

#ifndef __OBSERVER_SQL_EVENT_SQLEVENT_H__
#define __OBSERVER_SQL_EVENT_SQLEVENT_H__

#include <string>
#include "common/seda/stage_event.h"

class SessionEvent;
class Stmt;
// 声明了两个类SessionEvent和Stmt
// Stmt是关于陈述语句的类
// SessionEvent是StageEvent的继承
struct Query;
// 各种查询语句的结构体


// SQLStageEvent又是StageEvent的继承
class SQLStageEvent : public common::StageEvent
{
public:
  // 构造函数和析构函数
  SQLStageEvent(SessionEvent *event, const std::string &sql);
  virtual ~SQLStageEvent() noexcept;

  // 调用这个函数能够得到SQLStageEvent的private成员session_event_
  SessionEvent *session_event() const
  {
    return session_event_;
  }

  // 调用的时候分别能返回这个类的三个私有成员
  const std::string &sql() const { return sql_; }
  Query *query() const { return query_; }
  Stmt *stmt() const { return stmt_; }

  // 调用这三个函数能把函数的形参数据传递给类成员
  void set_sql(const char *sql) { sql_ = sql; }
  void set_query(Query *query) { query_ = query; }
  void set_stmt(Stmt *stmt) { stmt_ = stmt; }

private:
  SessionEvent *session_event_ = nullptr;
  std::string sql_;
  Query *query_ = nullptr;
  Stmt *stmt_ = nullptr;
};

#endif  //__SRC_OBSERVER_SQL_EVENT_SQLEVENT_H__
